﻿using com.fmtx.IDal;
using com.fmtx.Model;
using fmtx.Framework.DALFactory;
using fmtx.Framework.SqlHelper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace website.Areas.Admin.Controllers
{
    public class CountryController : AdminBaseController
    {
        //
        // GET: /Admin/Country/
        private ICountry country = DataAccess<ICountry>.GetObject();

        private IArea area = DataAccess<IArea>.GetObject();

        public ActionResult Index()
        {
            return View();
        }

        public ActionResult AddCountry()
        {
            SqlHelper.OpenConn("SQLConnString");
            var arealist = area.GetAll();
            foreach (var a in arealist)
            {
                var asql = "SELECT [Areaid]  FROM [trip_area] where Chinesename=@Chinesename";
                System.Data.SqlClient.SqlParameter[] parm = { new System.Data.SqlClient.SqlParameter("@Chinesename", a.Name) };
                object obj= SqlHelper.ExecuteScalar("SQLConnString", System.Data.CommandType.Text,asql,parm);

                var sql = "select Chinesename,Englishname,Pinyin,Lat,Lng,Content from trip_area where Areatype=2 and Parareaid=@Parareaid";
                System.Data.SqlClient.SqlParameter[] parm1 = { new System.Data.SqlClient.SqlParameter("@Parareaid", Convert.ToInt32(obj)) };
                var dt = SqlHelper.ExecuteDataTable("SQLConnString", System.Data.CommandType.Text, sql, parm1);
                foreach (System.Data.DataRow item in dt.Rows)
                {
                    Country model = new Country();
                    model.Name = item["Chinesename"].ToString();
                    model.EnName = item["Englishname"].ToString();
                    model.PingYin = item["Pinyin"].ToString();
                    model.Lat = Convert.ToDouble(item["Lat"]);
                    model.Lng = Convert.ToDouble(item["Lng"]);
                    model.Summary = item["Content"].ToString();
                    model.AreaName = a.Name;
                    model.AreaId = a.Id;
                    country.Add(model);
                }
            }
            
            SqlHelper.CloseConn();
            return View();
        }

    }
}
